var utils = require("../utils/utils");
var ocr_utils = require("../utils/ocr_utils");
var in_task = require("./inTask");
var point_map = require("./pointMap");

var treasure = {
  go_page_from_home() {
    var logger = utils.create_logger("treasure go_page_from_home: ");
    logger();
    if (ocr_utils.screen_exists_text_all(["首页", "视频"], true)) {
      logger("SUCCESS");
      utils.click_point.apply(
        utils,
        utils.get_size_point(point_map["首页任务"], 1080, 2340)
      );
      var interval = utils.get_random_interval(5, 0, 2, 1000);
      logger("等待--" + interval / 1000 + "--秒后开始判断是否开宝箱");
      sleep(interval);
      this.init();
    } else {
      logger("NOT FOUND");
    }
  },
  is_over_today: false,
  init() {
    var logger = utils.create_logger("treasure init: ");
    if (this.is_over_today) {
      logger("今天的开宝箱任务已经全部完毕");
      return;
    }
    in_task.init();
    var ui_text = utils.click_text("开宝箱得金币");
    if (ui_text) {
      logger("找到【开宝箱得金币】");
      sleep(utils.get_random_interval(5, 0, 2, 1000));
      this.run();
      return;
    }
    logger("没找到【开宝箱得金币】");
    if (utils.exists_text_starts_with("明天再来")) {
      this.is_over_today = true;
      logger("找到--明天再来--,今天的开宝箱任务已经全部完毕");
    }
    this.next();
  },
  run() {
    in_task.init();
    this.next();
  },
  next() {
    console.log("treasure next");
  },
};
module.exports = treasure;
